package com.tao.service;

import com.tao.entity.UserEntity;
import com.tao.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/insertUser")
    public String insertUser(String userName, Integer age){
        int update = jdbcTemplate.update("insert into users values(null,?,?)",userName,age);
        return update >0 ? "success" :"fail";
    }

    @RequestMapping("/mybatisfindbyId")
    public UserEntity mybatisfindbyId(Integer id){
        return userMapper.selectByUserId(id);
    }

    @RequestMapping("/inertUserMybatis")
    public String inertUserMybatis(String userName,Integer age){
        int insert = userMapper.insertUser(userName,age);
        return insert > 0 ? "success":"fail";
    }

    @RequestMapping("/myIndex")
    public String myIndex(){
        return "taoziss12";
    }


}
